package com.ruoyi.web.controller.mobile;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mobile.domain.Lesson;
import com.ruoyi.mobile.model.vo.LessonVo;
import com.ruoyi.mobile.service.ILessonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 课程视频Controller
 * 
 * @author ruoyi
 * @date 2022-09-26
 */
@RestController
@RequestMapping("/mobile/lesson")
public class LessonController extends BaseController
{
    @Autowired
    private ILessonService lessonService;

    /**
     * 查询课程视频列表
     */
    @PreAuthorize("@ss.hasPermi('mobile:lesson:list')")
    @GetMapping("/list")
    public TableDataInfo list(Lesson lesson)
    {
        startPage();
        List<Lesson> list = lessonService.selectLessonList(lesson);
        return getDataTable(list);
    }

    /**
     * 导出课程视频列表
     */
    @PreAuthorize("@ss.hasPermi('mobile:lesson:export')")
    @Log(title = "课程视频", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Lesson lesson)
    {
        List<Lesson> list = lessonService.selectLessonList(lesson);
        ExcelUtil<Lesson> util = new ExcelUtil<Lesson>(Lesson.class);
        util.exportExcel(response, list, "课程视频数据");
    }

    /**
     * 获取课程视频详细信息
     */
    @PreAuthorize("@ss.hasPermi('mobile:lesson:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(lessonService.selectLessonById(id));
    }

    /**
     * 新增课程视频
     */
    @PreAuthorize("@ss.hasPermi('mobile:lesson:add')")
    @Log(title = "课程视频", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Lesson lesson)
    {
        return toAjax(lessonService.insertLesson(lesson));
    }

    /**
     * 修改课程视频
     */
    @PreAuthorize("@ss.hasPermi('mobile:lesson:edit')")
    @Log(title = "课程视频", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Lesson lesson)
    {
        return toAjax(lessonService.updateLesson(lesson));
    }

    /**
     * 删除课程视频
     */
    @PreAuthorize("@ss.hasPermi('mobile:lesson:remove')")
    @Log(title = "课程视频", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(lessonService.deleteLessonByIds(ids));
    }


    @GetMapping("/all")
    public AjaxResult getAllLesson() {
        List<LessonVo> list = lessonService.getAllLesson();
        return AjaxResult.success(list);
    }
}
